<p>This rule raises an issue when a negated expression is directly compared using equality operators (<code>===</code>, <code>!==</code>,
<code>==</code>, <code>!=</code>).</p>
<h2>Why is this an issue?</h2>
<p>Using a negated expression in an equality check is almost always a logical error that leads to unexpected behavior.</p>
<p>When you write <code>!foo === bar</code>, JavaScript parses this as <code>(!foo) === bar</code> due to operator precedence. This compares the
boolean result of <code>!foo</code> with the value of <code>bar</code>, which is rarely the intended logic.</p>
<p>For example, if <code>foo</code> is <code>"hello"</code> and <code>bar</code> is <code>"world"</code>, then <code>!foo === bar</code> becomes
<code>false === "world"</code>, which evaluates to <code>false</code>. This is likely not what you wanted to check.</p>
<p>This pattern usually occurs when developers:</p>
<ul>
  <li> Intend to write <code>foo !== bar</code> but accidentally add the negation operator </li>
  <li> Want to negate the entire comparison but forget the parentheses: <code>!(foo === bar)</code> </li>
  <li> Misunderstand JavaScript’s operator precedence rules </li>
</ul>
<p>These mistakes can cause conditional statements to behave incorrectly, leading to bugs that are difficult to spot during code review.</p>
<h3>What is the potential impact?</h3>
<p>This issue can cause logical errors in your application’s control flow. Conditional statements may not work as expected, potentially leading
to:</p>
<ul>
  <li> Incorrect branching in if-else statements </li>
  <li> Unexpected behavior in loops and filters </li>
  <li> Security vulnerabilities if the faulty logic affects authentication or authorization checks </li>
  <li> Data corruption if the logic controls data processing operations </li>
</ul>
<h3>How to fix?</h3>
<p>Replace the negated equality check with the correct inequality operator. Use <code>!==</code> instead of <code>!expression ===</code> and
<code>===</code> instead of <code>!expression !==</code>.</p>
<h4>Non-compliant code example</h4>
<pre data-diff-id="1" data-diff-type="noncompliant">
if (!foo === bar) { // Noncompliant
  // This compares (!foo) with bar
  doSomething();
}
</pre>
<h4>Compliant code example</h4>
<pre data-diff-id="1" data-diff-type="compliant">
if (foo !== bar) {
  // This correctly checks if foo is not equal to bar
  doSomething();
}
</pre>
<h3>Documentation</h3>
<ul>
  <li> <a href="https://github.com/sindresorhus/eslint-plugin-unicorn#readme">eslint-plugin-unicorn</a> - Rule <a
  href="https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/no-negation-in-equality-check.md">no-negation-in-equality-check</a>
  </li>
  <li> MDN - Operator Precedence - <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence">Explains
  how JavaScript evaluates operators in different orders</a> </li>
  <li> MDN - Equality Operators - <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality">Documentation on
  JavaScript’s equality and inequality operators</a> </li>
</ul>
